//
//  ZCRelayView.swift
//  weibo
//
//  Created by 张城 on 16/7/23.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit
import SnapKit

class ZCRelayView: UIView {

    
    var relayViewBottomConstraint: Constraint?
    
    
    
    var homeCellViewModel: ZCHomeCellViewModel? {
        didSet{
    
            self.relayContentLabel.text = homeCellViewModel?.homeModel?.retweeted_status?.text
            
            
            
            
            self.relayViewBottomConstraint?.uninstall()
            if homeCellViewModel?.homeModel?.retweeted_status?.pic_urls?.count > 0 {
                picturesView.pictures = homeCellViewModel?.homeModel?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints(closure: { (make) in
                    self.relayViewBottomConstraint = make.bottom.equalTo(picturesView.snp_bottom).offset(10).constraint
                })
                picturesView.hidden = false
                
                
            }else{
                self.snp_makeConstraints(closure: { (make) in
                    self.relayViewBottomConstraint = make.bottom.equalTo(relayContentLabel.snp_bottom).offset(10).constraint
                })
                picturesView.hidden = true
            }
            
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        backgroundColor = UIColor.groupTableViewBackgroundColor()
        addSubview(relayContentLabel)
        addSubview(picturesView)
        
        relayContentLabel.snp_makeConstraints { (make) in
            make.top.leading.equalTo(10)
        }
        
        picturesView.snp_makeConstraints { (make) in
            make.top.equalTo(relayContentLabel.snp_bottom).offset(10)
            make.leading.equalTo((SCREENW-250)/2)
        }
        
        self.snp_makeConstraints { (make) in
            self.relayViewBottomConstraint = make.bottom.equalTo(picturesView.snp_bottom).offset(10).constraint
        }
    }
    
    
    private lazy var relayContentLabel: UILabel = UILabel(textColor: UIColor.grayColor(), textFont: 14, maxWidth: SCREENW - 40)
    
    private lazy var picturesView: ZCPicturesView = ZCPicturesView()
    
}
